﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PointTracker
{
    public class Student
    {
        private string _fname = "";
        private string _lname = "";
        private string _duId = "";
        private int _points = 0;
        private int _classCrn = 0;

        public Student(string fnameIn, string lnameIn, string duidIn, int pointsIn, int classCrnIn)
        {
            _fname = fnameIn;
            _lname = lnameIn;
            _duId = duidIn;
            _points = pointsIn;
            _classCrn = classCrnIn;
        }

        public string fname
        {
            get { return _fname; }
            set { _fname = value; }
        }
        public string lname
        {
            get { return _lname; }
            set { _lname = value; }
        }
        public string duId
        {
            get { return _duId; }
            set { _duId = value; }
        }
        public int points
        {
            get { return _points; }
            set { _points = value; }
        }
        public int classCRN
        {
            get { return _classCrn; }
            set { _classCrn = value; }
        }

        public static Boolean addStudents(string str, int crn)
        {
            string[] lines = Regex.Split(str, "\r\n");
            List<Student> students = new List<Student>();
            string[] temp = new string[3];
            foreach (string line in lines)
            {
                temp = line.Split(',');
                students.Add(new Student(temp[1], temp[0], temp[2], 0, crn));
            }
            return DatabaseManager.addStudents(students, crn);
        }

        public static List<Student> getStudents(int crn)
        {
            List<List<string>> studentList = DatabaseManager.getStudents(crn);
            List<Student> students = new List<Student>();

            foreach (List<string> student in studentList)
            {
                students.Add(new Student(student[0], student[1], student[2], Int32.Parse(student[3]), crn));
            }
            return students;
        }
    }
}
